home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / arexx_macros / lwscenemacros / chkscenes.rexx < prev    next >
OS/2 REXX Batch file  |  1994-09-05  |  8KB  |  262 lines

  1. /*
  2.    ChkScenes.rexx
  3.  
  4.    Copyright (C) 1994 Earl C. Terwilliger
  5.                 Phone (606)-723-5718
  6.  
  7.       Internet: AISTERWI@ACS.EKU.EDU
  8.    Conmpuserve: 70575,1330
  9.  
  10.    Non-Commercial USE granted to ALL !!!
  11.  
  12.    One of the problems with giving a LW scene
  13.    to someone else is that you have to give
  14.    the other files that are referenced in
  15.    the scene file too. The reference in the
  16.    LW scene file is to the complete file name
  17.    including drive and path. You can easily
  18.    forget to include a file when copying your
  19.    scene and files to diskette.
  20.  
  21.    ChkScenes.rexx checks Lightwave Scene files to make
  22.    sure that the file names referenced in the scene
  23.    do indeed exist. Any referenced object file is
  24.    also checked to verify the existance of maps
  25.    (texture, reflection) that the object is using.
  26.  
  27.    If a file is not found that is referenced, an error
  28.    message and the file name is displayed along with
  29.    the LW scene command which references the file name.
  30.    Some files may not be found due to no reference to
  31.    their drive:directory. LW layouts default is then to
  32.    look for those files in its default location which
  33.    is OK if they are found there. This script only
  34.    checks the directory structure if the drive:directory
  35.    is specified. (It also checks the path from the
  36.    drive:directory of the specified scene file for
  37.    any files which are referenced by it that do not
  38.    have a drive:directory prefix.)
  39.  
  40.    Syntax: rx ChkScenes drive:[directory]
  41.  
  42.    The only required parameter is the drive.
  43.    The directory is optional. (Actually if you have
  44.    only one directory to check, it is faster to
  45.    specify it, since this AREXX script will
  46.    recursively check thru each sub-directory
  47.    looking for scene files which may take a while.
  48.  
  49.    Note: The ChkScenes.rexx script checks an
  50.    entire drive:[directory] for all LW scenes files
  51.    it finds whereas the ChkScene.rexx script only
  52.    checks a single LW scene file.
  53.  
  54. */
  55.  
  56. /* TRACE(RESULTS) */
  57. OPTIONS RESULTS
  58. parse arg dir
  59.  
  60. if arg() = 0    then call syntax()
  61. if ~exists(dir) then call syntax()
  62.  
  63. if ~show('L',"rexxsupport.library") then do
  64.     if addlib('rexxsupport.library',0,-30,0) then
  65.         say "Added rexxsupport.library."
  66.     else do
  67.         say "Error: addlib() of rexxsupport.library failed."
  68.         exit 10
  69.     end
  70. end
  71.  
  72. call main(dir)
  73. say
  74. say '<- Check Scenes Completed ->'
  75. exit 0
  76.  
  77. main: procedure
  78. parse arg dir
  79. OPTIONS RESULTS
  80. filelist = showdir(dir,'ALL')
  81. if right(dir,1) ~= ":" then dir = dir||"/"
  82. i = 1
  83. do while word(filelist,i) ~= ''
  84.     filename = dir||word(filelist,i)
  85.     type = statef(filename)
  86.     if (word(type,1) = 'DIR') then do
  87.         call main(filename)
  88.         end
  89.     else do
  90.         if (word(type,1) = 'FILE') then do
  91.             call check(filename)
  92.         end
  93.     end
  94.     i = i + 1
  95. end
  96. return 0
  97.  
  98. check: procedure expose dir
  99. parse arg file
  100. OPTIONS RESULTS
  101. open('infile',file,'R')
  102. instring=readln('infile')
  103. if (pos('LWSC',instring) ~= 1) then do
  104.   close('infile')
  105.   return 1
  106. end
  107.  
  108. say
  109. say '[Scene File Name]' file
  110.  
  111. if (index(file,':') ~= 0) then do
  112.      temp = translate(file,"  ","/:"," ")
  113.      tempwords = words(temp)
  114.      name = word(temp,tempwords)
  115.      source = left(file,length(file)-length(name))
  116. end  
  117. else source = dir
  118. if (right(source,1) ~= ':') then do
  119.     if (right(source,1) ~= '/') then source = source||'/'
  120. end
  121.  
  122. do while eof('infile')=0
  123.      instring = readln('infile')
  124.      lwcmd = word(instring,1)
  125.      c = index(lwcmd,'Load')
  126.      if (index(instring,':') ~= 0) then do
  127.          if (index(instring,'/') ~= 0) then c = c + 1
  128.      end
  129.      if (c > 0) then do
  130.         filename = word(instring,2)
  131.         if (index(instring,':') = 0) then do
  132.             if (left(filename,1) ~= '/') then filename = source||filename
  133.             else filename = source||strip(filename,'L','/')
  134.         end
  135.         temp = upper(translate(filename,"  ","/:"," "))
  136.         c = showlist('A',word(temp,1))
  137.         c = c + showlist('H',word(temp,1))
  138.         if (c = 0) then do
  139.             say instring
  140.             call errmsg('Volume Not Mounted -  ERROR')
  141.         end
  142.         else if (~exists(filename)) then do
  143.                   temp = translate(filename,"  ","/:"," ")
  144.                   tempwords = words(temp)
  145.                   name = word(temp,tempwords)
  146.                   objname = source||'objects/'||name
  147.                   if (exists(objname)) then do
  148.                       say filename 'exists as' objname
  149.                       filename = objname
  150.                       if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
  151.                   end
  152.                   else do
  153.                       say instring
  154.                       call errmsg('File not Found -  ERROR')
  155.                   end
  156.              end
  157.         else do
  158.             say instring ' [OK]'
  159.             if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
  160.         end
  161.      end
  162. end
  163. close('infile')
  164. say
  165. say '<- Check Scene completed for file ->' file
  166. return 0
  167.  
  168. syntax:
  169. say
  170. say 'Syntax: rx ChkScenes drive:[directory]'
  171. say 
  172. exit 10
  173.  
  174. readlwob: PROCEDURE EXPOSE source filename
  175. OPTIONS RESULTS
  176.  
  177. open('lwobfile',filename,'R')
  178. objstring = readch('lwobfile',12)
  179.  
  180. type = substr(objstring,9,4)
  181.  
  182. if (type ~= "LWOB") then do
  183.   close('lwobfile')
  184.   say filename
  185.   call errmsg('This is not a LW Object file! - ERROR')
  186.   return 10
  187. end
  188.  
  189. form   = substr(objstring,1,4)
  190. length = c2d(substr(objstring,5,4),4)
  191. length = length + 8
  192.  
  193. say 'Reading from' filename
  194. /* say 'Object file length is' length 'bytes' */
  195.  
  196. open('lwobout',destname,'W')
  197.  
  198. do while eof('lwobfile')=0
  199.     objstring=readch('lwobfile',8)
  200.     if (eof('lwobfile') = 1) then break
  201.     chunk  = substr(objstring,1,4)
  202.     length = c2d(substr(objstring,5,4),4)
  203.     /* say 'Chunk Type is' chunk 'with a length of' length 'bytes' */
  204.     if (chunk ~= "SURF") then seek('lwobfile',length,'C')
  205.     else do
  206.         objstring = readch('lwobfile',length)
  207.         surfacepos = pos('00'x,objstring,1)
  208.         surface  = substr(objstring,1,(surfacepos-1))
  209.         surfacepos = surfacepos + (surfacepos // 2) + 1
  210.         say 'Surface Name:' surface
  211.         do while (surfacepos < length)
  212.             subchunk = substr(objstring,surfacepos,4)
  213.             /* say 'Subchunk  ' subchunk */
  214.             surfacepos = surfacepos + 4
  215.             len = c2d(substr(objstring,surfacepos,2),4)
  216.             surfacepos = surfacepos + 2
  217.             image = ""
  218.             if (subchunk = "TIMG") then do
  219.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  220.                 say 'Texture Image ->' image
  221.             end
  222.             if (subchunk = 'RIMG') then do
  223.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  224.                 say 'Reflection Image ->' image
  225.             end
  226.             if (image = "(none)") then image = ""
  227.             if (image ~= "") then do
  228.                 if (index(image,':') = 0) then do
  229.                     if (left(image,1) ~= '/') then fullimage = source||image
  230.                     else fullimage = source||strip(image,'L','/')
  231.                 end
  232.                 else fullimage = image
  233.                 temp = translate(fullimage,"  ","/:"," ")
  234.                 tempwords = words(temp)
  235.                 name = word(temp,tempwords)
  236.                 directory = left(fullimage,length(fullimage)-length(name))
  237.                 if (~exists(directory)) then do
  238.                     if (exists(source||"images")) then fullimage = source||'images/'||name
  239.                 end
  240.                 if (index(image,"(sequence)",1) = 0) then do
  241.                     if (~exists(fullimage)) then  do
  242.                          say fullimage
  243.                          call errmsg('File Not Found - ERROR')
  244.                      end
  245.                 end    
  246.             end
  247.             surfacepos = surfacepos + len
  248.         end
  249.     end
  250. end
  251.  
  252. close('lwobfile')
  253. return 0
  254.  
  255. errmsg: procedure
  256. parse arg msg
  257. len = length(msg) - 1
  258. errmsg = '|___________________________________________________________________________'
  259. errmsg = overlay(msg,errmsg,length(errmsg)-len,len+1)
  260. say errmsg
  261. return 0
  262.